package com.example.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * @功能:
 * @User Lmy
 * @Creat 2020/7/10 16:34
 * @Compony 永远相信美好的事情即将发生
 */
public class TestView extends View {
    public TestView(Context context) {
        super(context);
    }

    public TestView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public TestView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    Paint paint = new Paint();

    @SuppressLint("ResourceAsColor")
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //设置画笔颜色
        paint.setColor(0xFF03DAC5);
        //设置文字大小
        paint.setTextSize(100);
        //设置回值模式
//        paint.setStyle(Paint.Style.FILL);//填充
        paint.setStyle(Paint.Style.STROKE);//不填充

        //开启抗锯齿 解决毛边问题
        paint.setAntiAlias(true);
        //颜色填充画布
        canvas.drawColor(Color.BLACK);
        canvas.drawText("hahah", 150, 150, paint);
        //绘制圆形
//        canvas.drawCircle(500, 500, 400, paint);
        //绘制矩形
        canvas.drawRect(100, 100, 300, 300, paint);

        float[] points = {0, 0, 50, 50, 50, 100, 100, 50, 100, 100, 150, 50};
        paint.setStrokeWidth(10);
        paint.setStrokeCap(Paint.Cap.ROUND);//( ROUND )、平头 ( BUTT ) 和方头 ( SQUARE ) 三种，
        canvas.drawPoint(50, 50, paint);
        canvas.drawPoints(points, 2 /* 跳过两个数，即前两个 0 */,
                8 /* 一共绘制 8 个数（4 个点）*/, paint);


    }
}
